// 订单商品

const orderGoodsModel = require("../model/orderGoodsModel");



//增加匹配 
module.exports.insert = async function (content) {
    return await orderGoodsModel.create(content);
}


//删除匹配
module.exports.delete = async function (id) {
    return await orderGoodsModel.deleteOne({ _id: id });
}

//修改匹配
module.exports.update = async function (id, content) {
    return await orderGoodsModel.updateOne({ _id: id }, content);
}

//分页所有/条件查询
module.exports.findNo = async function (searchObj, page) {
    console.log(searchObj);
    let { current, size } = page;
    let total = await orderGoodsModel.countDocuments(searchObj);
    let totalPage = Math.ceil(total / size);
    let rows = await orderGoodsModel.find(searchObj)
    .populate({ path: 'goodsId' })
    .populate({ path: 'userId' })
    .populate({ path: 'shopId' })
    .populate({ path: 'adminId' })
    .populate({ path: 'addressesId' })
    .limit(parseInt(size)).skip((current - 1) * size);
    return { current, size, total, totalPage, rows };
}


// module.exports.findByFilmIdAndCinemaId = async function (filmId, cinemaId) {
//     return await orderGoodsModel
//         .find({ films: filmId, cinemas: cinemaId })
//         .populate({ path: 'films' })
//         .populate({ path: 'cinemas' });
// }








